<?php

/**
 * This is the model class for table "{{page_location_mapping}}".
 *
 * The followings are the available columns in table '{{page_location_mapping}}':
 * @property integer $mapping_id
 * @property integer $page_id
 * @property string $location_name
 * @property string $created_date
 * @property string $updated_date
 */
class PageLocationMapping extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return PageLocationMapping the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{page_location_mapping}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('page_id, location_name', 'required'),
			array('page_id', 'numerical', 'integerOnly'=>true),
			array('location_name', 'length', 'max'=>500),
			array('updated_date', 'default', 'value' => new CDbExpression('NOW()'), 'setOnEmpty' => false, 'on' => 'update'), 
			array('created_date,updated_date', 'default', 'value' => new CDbExpression('NOW()'), 'setOnEmpty' => false, 'on' => 'insert'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('mapping_id, page_id, location_name, created_date, updated_date', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'mapping_id' => 'Mapping',
			'page_id' => 'Page',
			'location_name' => 'Location Name',
			'created_date' => 'Created Date',
			'updated_date' => 'Updated Date',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search($id = null)
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('mapping_id',$this->mapping_id);
		if (!empty($id))
		$criteria->compare('page_id',$id);
		else
		$criteria->compare('page_id',$this->page_id);
		$criteria->compare('location_name',$this->location_name,true);
		$criteria->compare('created_date',$this->created_date,true);
		$criteria->compare('updated_date',$this->updated_date,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
	public static function getList($type, $arrParams = array())
    {
        switch ($type)
        {
            case 'LOCATIONS-BY-PAGE':
                return PageLocationMapping::model()->findAll('page_id=?',array($arrParams['page_id']));
                break;

        }
    }
}